package com.itheima.mapper;

import com.itheima.pojo.*;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

@Mapper
public interface OrdersMapper {

    /**
     * 统计页面总数量
     */
    @Select("select count(*) from orders")
    int count();

    /**
     * 分页查询
     */
    List<OrdersPage> OrdersPage(Date beginTime, Date endTime, String number, Integer page, Integer pageSize);

    /**
     * 提交订单
     */
    int submitOrder(Orders orders);

    /**
     * 订单列表
     */
    @Select("select id,orderTime,status,amount from orders  limit #{page},#{pageSize} ")
    List<OrdersList> OrdersList(Integer page, Integer pageSize);

    /**
     * 通过addressbook默认地址获取对象
     */
    @Select("select * from addressbook  where isDefault = 1")
    Addressbook selectAddressBook();

    /**
     * 查询orderdetails
     */
    @Select("select name,number from orderdetails where ordersId=#{ordeIid}")
    List<OrderDetails> selectOrderDetails(@Param("ordeIid")String id);

    /**
     * 添加订单
     */
    @Insert("insert into orderdetails values (#{id},#{name},#{image},#{number},#{ordersId},#{dishId},#{setmealId},#{dishFlavors},#{amount})")
    int insertOrderDetails(OrderDetails orderDetails);

    /**
     * 获取购物车对象
     */
    @Select("select * from shoppingcart ,user where user.id = shoppingcart.userId")
    List<ShoppingCart> selectListShoppingCart();

}
